﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;

namespace MyHealthByDesignWebsite.Models
{
    public partial class UserHealthHistory
    {
        //Description:  Model for user health history
        //Created:  Nov 2011
        //Programmer:  Bob Whiteis

        //pre-condition:  User health history information has been submitted
        //post-condition:  False has been return if there is invalid information
        public bool IsValid
        {
            get { return (GetRuleViolations().Count() == 0); }
        }

        //pre-condition:  User health history information has been submitted
        //post-condition:  excepiton is thrown if invalid data was entered
        partial void OnValidate(ChangeAction action)
        {

            if (!IsValid)
            {
                throw new ApplicationException("Rule violations prevent saving");
            }
           
        }

        //pre-condition:  User health history information has been submitted
        //post-condition:  List of rules violations is return
        public IEnumerable<RuleViolation> GetRuleViolations()
        {
            if (UHH_pregnant == "" || UHH_pregnant == null)
                yield return new RuleViolation("Please enter pregnancy information.", "UHH_pregnant");
             yield break;
        }
    }
}